﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;

namespace Ewts.BaseData
{
    public partial class GoodsModify : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(id);
                }
            }
        }

        private void ShowInfo(int id)
        {
            DataLib.BLL.Goods bll = new DataLib.BLL.Goods();
            DataLib.Model.Goods model = bll.GetModel(id);
            this.lblid.Text = model.id.ToString();
            this.txtgoodsName.Text = model.goodsName;
            txtRemark.Text = model.remark;
            ddlgoodsType.SelectedValue = model.goodsType;
            this.txtdescribe.Text = model.describe;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtgoodsName.Text.Trim().Length == 0)
            {
                strErr += "物品编码不能为空！\\n";
            }
          

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int id = int.Parse(this.lblid.Text);
            string goodsName = this.txtgoodsName.Text;
            string goodsType = ddlgoodsType.SelectedValue;
            string describe = this.txtdescribe.Text;
            string remark = txtRemark.Text;

            DataLib.Model.Goods model = new DataLib.Model.Goods();
            model.id = id;
            model.goodsName = goodsName;
            model.goodsType = goodsType;
            model.describe = describe;
            model.remark = remark;

            DataLib.BLL.Goods bll = new DataLib.BLL.Goods();
            bll.Update(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "GoodsList.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("GoodsList.aspx");
        }
    }
}